package com.gxa.jjty.cjr.controller;

import com.gxa.jjty.cjr.service.SearchService;
import com.gxa.jjty.core.common.ExceptionCode;
import com.gxa.jjty.core.exception.BusinessException;
import com.gxa.jjty.core.util.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @author : 宸濯
 * Date: 2021/12/13 10:56
 * Description:
 * Version: V1.0
 */
@Api(tags = "模糊查询api")
@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    SearchService searchService;

    @GetMapping("/findByName")
    @ApiOperation("根据内容模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id"),
            @ApiImplicitParam(name = "name",value = "搜索内容")
    })
    public Map<String,Object> findByName(Long id,String name) throws BusinessException {
        if (id==null){
            throw new BusinessException(ExceptionCode.ID_NOTNULL);
        }
        if (StringUtil.isEmpty(name)){
            throw new BusinessException(ExceptionCode.ERROR);
        }
        return searchService.findByName(id,name);
    }

    @GetMapping("/searchRecode")
    @ApiOperation("搜索记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "用户id")
    })
    public Map<String, Object> searchRecode(Long id) throws BusinessException {
        if (id==null){
            throw new BusinessException(ExceptionCode.ID_NOTNULL);
        }
        return searchService.searchRecode(id);
    }
}
